package com.changgou.thymeleaf.controller;

import com.changgou.thymeleaf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("demo")
public class DemoController {

    @GetMapping("/test1")
    public String test1(Model model,String id){

        System.out.println(id);

        List<User> users = new ArrayList<User>();
        users.add(new User(1,"张三","深圳"));
        users.add(new User(2,"李四","北京"));
        users.add(new User(3,"王五","武汉"));
        model.addAttribute("userList",users);

        Map<String,Object> dataMap = new HashMap<String,Object>();
        dataMap.put("No","123");
        dataMap.put("address","深圳");
        model.addAttribute("dataMap",dataMap);

        //存储一个数组
        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);
        //日期
        model.addAttribute("now",new Date());
        //if条件
        model.addAttribute("age",22);
        //返回数据
        model.addAttribute("hello","长颈鹿");
        //网页
        return "demo";
    }
}
